package org.springblade.modules.app.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.app.entity.Advertise;
import org.springblade.modules.app.service.IAdvertiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图 控制器
 *
 * @author kingk
 */
@RestController
@RequestMapping("blade-app/advertise")
public class AdvertiseController extends BladeController {


    @Autowired
    private IAdvertiseService advertiseService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    public R<Advertise> detail(Advertise advertise) {
        Advertise detail = advertiseService.getOne(Condition.getQueryWrapper(advertise));
        return R.data(detail);
    }

    /**
     * 分页 轮播图
     */
    @GetMapping("/list")
    public List<Advertise> list(Advertise params) {
        List<Advertise> result = advertiseService.list(Wrappers.query(params));
        return result;
    }

    /**
     * 自定义分页 轮播图
     */
    @GetMapping("/page")
    public R<IPage<Advertise>> page(Page page, Advertise params) {
        IPage<Advertise> result = advertiseService.page(page, Wrappers.query(params));
        return R.data(result);
    }

    /**
     * 新增 轮播图
     */
    @PostMapping("/save")
    public R save(@RequestBody Advertise advertise) {
        return R.status(advertiseService.save(advertise));
    }

    /**
     * 修改 轮播图
     */
    @PostMapping("/update")
    public R update(@RequestBody Advertise advertise) {
        return R.status(advertiseService.updateById(advertise));
    }

    /**
     * 新增或修改 轮播图
     */
    @PostMapping("/submit")
    public R submit(@RequestBody Advertise advertise) {
        return R.status(advertiseService.saveOrUpdate(advertise));
    }


    /**
     * 删除 轮播图
     */
    @PostMapping("/remove")
    public R remove(@RequestParam String ids) {
        return R.status(advertiseService.removeByIds(Func.toLongList(ids)));
    }


}
